<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/common/session.jsp"%>
<c:set var="deptParentId" value="${param.deptParentId}" />
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
    <title>信息部管理</title>
    <script type="text/javascript" src="${ctx}/js/xtable.js"></script>
    <script type="text/javascript" src="${ctx}/js/validator.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type="text/javascript" src="${ctx}/js/loading.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/DeptService.js"></script>
</head>
<body>
<img src="${ctx}/images/common/button_insert.jpg" title="添加信息总部" style="cursor:pointer" onclick="insertDept()"/>
<SCRIPT LANGUAGE="JavaScript" type="">
    var deptThead = new Array(
            new XThead("logo"),
            new XThead("信息部名称"),
            new XThead("所在地区"),
            new XThead("联系人"),
            new XThead("手机号"),
            new XThead("操作")
    );

    var deptXTable = new XTable("dept", deptThead, true);

    deptXTable.XTbodyArray = function (model) {
        var deptUrl = "";
        <c:if test="${empty deptParentId}">
        deptUrl = "<a href='#' onclick=addTabDept('" + model.deptId + "')>【分部管理】</a>";
        </c:if>
        var array = new Array(
                new XTbody("dept", "<img width=50 height=50 src='${ctx}" + model.dept.deptLogo + "' onerror='loadDefaultPhoto(this)' />", null, null, null, "center"),
                new XTbody("dept", model.dept.deptName, null, null, null, "center"),
                new XTbody("dept", model.dept.province.provinceName + model.dept.city.cityName + model.dept.district.districtName, null, null, null, "center"),
                new XTbody("dept", model.user != null ? model.user.userName : null, null, null, null, "center"),
                new XTbody("dept", model.user != null ? model.user.userMobile : null, null, null, null, "center"),
                new XTbody("dept", "<a href='${ctx}/dept/dept_manage.jsp?deptId=" + model.deptId + "&deptParentId=${deptParentId}'>【编辑信息部】</a>" +
                        "<a href='#' onclick=\"addTabStaff('" + model.deptId + "', '" + model.dept.deptParentId + "')\">【员工管理】</a>" +
                        deptUrl +
                        "<a href='${ctx}/dept/dept_child_list.jsp?deptId=" + model.deptId + "'>【收费记录】</a>",
                        null, null, null, "center")
        );

        return array;
    }
    deptXTable.getXList = function (page){
        var dept = new Dept();
        <c:if test="${empty deptParentId}">
        dept.deptType = 1;
        </c:if>
        <c:if test="${!empty deptParentId}">
        dept.deptType = 0;
        dept.deptParentId = "${deptParentId}";
        </c:if>

        DeptService.selectDeptUserList(dept, function(list){deptXTable.addTable(list);});
    }
</SCRIPT>
</body>
</html>
<script type="text/javascript">
    deptXTable.goPage(1);
    function insertDept() {
        location = "${ctx}/dept/dept_manage.jsp?deptParentId=${deptParentId}";
    }
    function loadDefaultPhoto(obj) {
        obj.onerror=null;
        obj.src="${ctx}/images/head.png";
    }
    function addTabStaff(deptId, deptParentId) {
        location = "${ctx}/user/staff_list.jsp?deptId=" + deptId + "&deptParentId=" + deptParentId;
        <%--parent.addTab(33724, "员工管理", "${ctx}/user/staff_list.jsp?deptId=" + deptId + "," + deptParentId);--%>
    }
    function addTabDept(deptParentId) {
        parent.addTab(33725, "分部管理", "${ctx}/dept/dept_list.jsp?deptParentId=" + deptParentId);
    }
</script>